/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package travelexperts;

import java.sql.SQLException;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class MainForm extends javax.swing.JFrame {

    public static DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);

    /**
     * Creates new form MainForm
     */
    public MainForm() {
        initComponents();
        refreshInactiveAgent();
        refreshActiveAgent();
        refreshProduct();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("travelexperts?zeroDateTimeBehavior=convertToNullPU").createEntityManager();
        agentsQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Agents a");
        agentsList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(agentsQuery.getResultList());
        packagesQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT p FROM Packages p");
        packagesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(packagesQuery.getResultList());
        agentsQuery2 = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a.agentId FROM Agents a WHERE a.agtPosition = :agtPosition");
        agentsQuery2.setParameter("agtPosition", "Inactive");
        agentsList2 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : agentsQuery2.getResultList();
        agentsQuery1 = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a.agentId FROM Agents a WHERE a.agtPosition <> :agtPosition");
        agentsQuery1.setParameter("agtPosition", "Inactive");
        agentsList1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : agentsQuery1.getResultList();
        agenciesQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a.agencyId FROM Agencies a ");
        agenciesList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : agenciesQuery.getResultList();
        convert1 = new travelexperts.Convert();
        currencyConvert1 = new travelexperts.currencyConvert();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        tpAll = new javax.swing.JTabbedPane();
        pAgents = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabAgents = new javax.swing.JTable();
        txtId = new javax.swing.JTextField();
        txtFirstName = new javax.swing.JTextField();
        txtMiddleName = new javax.swing.JTextField();
        txtLastName = new javax.swing.JTextField();
        txtBusPhone = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        cmbPosition = new javax.swing.JComboBox();
        lblId = new javax.swing.JLabel();
        lblFirstName = new javax.swing.JLabel();
        lblMiddle = new javax.swing.JLabel();
        lblLastName = new javax.swing.JLabel();
        lblBusPhone = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        lblPosition = new javax.swing.JLabel();
        lblAgencyId = new javax.swing.JLabel();
        btnAgentsNew = new javax.swing.JButton();
        btnAgentsAdd = new javax.swing.JButton();
        btnAgentsUpdate = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        cmbAgnts = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        cmbActiveAgents = new javax.swing.JComboBox();
        jScrollPane5 = new javax.swing.JScrollPane();
        lCust = new javax.swing.JList();
        btnMoveCust = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        lSelectCust = new javax.swing.JList();
        cmbAgency = new javax.swing.JComboBox();
        btnAgentsDel = new javax.swing.JButton();
        pPackages = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabPackages = new javax.swing.JTable();
        txtName = new javax.swing.JTextField();
        txtId1 = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        lblStartDate = new javax.swing.JLabel();
        lblEndDate = new javax.swing.JLabel();
        lblPrice = new javax.swing.JLabel();
        lblComm = new javax.swing.JLabel();
        lblDesc = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();
        lblId1 = new javax.swing.JLabel();
        btnPackagesNew = new javax.swing.JButton();
        btnPackagesAdd = new javax.swing.JButton();
        btnPackagesUpdate = new javax.swing.JButton();
        btnPackagesDel = new javax.swing.JButton();
        txtStartDate = new javax.swing.JTextField();
        txtEndDate = new javax.swing.JTextField();
        cbtnStartDate = new net.sourceforge.jcalendarbutton.JCalendarButton();
        cbtnEndDate = new net.sourceforge.jcalendarbutton.JCalendarButton();
        txtPrice = new javax.swing.JTextField();
        txtCommission = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        lProducts = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        lProductSupplier = new javax.swing.JList();
        btnMoveprod = new javax.swing.JButton();
        btnAddProd = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setRollover(true);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/travelexperts/Actions-dialog-close-icon.png"))); // NOI18N
        jButton1.setToolTipText("Close");
        jButton1.setAutoscrolls(true);
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setMaximumSize(new java.awt.Dimension(25, 25));
        jButton1.setMinimumSize(new java.awt.Dimension(25, 25));
        jButton1.setPreferredSize(new java.awt.Dimension(25, 25));
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jToolBar1.add(jButton1);

        tpAll.setPreferredSize(new java.awt.Dimension(1080, 600));
        tpAll.setRequestFocusEnabled(false);

        tabAgents.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, agentsList, tabAgents, "agentTab");
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agentId}"));
        columnBinding.setColumnName("Agent Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agtFirstName}"));
        columnBinding.setColumnName("Agt First Name");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agtMiddleInitial}"));
        columnBinding.setColumnName("Agt Middle Initial");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agtLastName}"));
        columnBinding.setColumnName("Agt Last Name");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agtBusPhone}"));
        columnBinding.setColumnName("Agt Bus Phone");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agtEmail}"));
        columnBinding.setColumnName("Agt Email");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agtPosition}"));
        columnBinding.setColumnName("Agt Position");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${agencyId}"));
        columnBinding.setColumnName("Agency Id");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        tabAgents.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tabAgentsMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tabAgents);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agentId}"), txtId, org.jdesktop.beansbinding.BeanProperty.create("text"), "agentid");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agtFirstName}"), txtFirstName, org.jdesktop.beansbinding.BeanProperty.create("text"), "agenFN");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agtMiddleInitial}"), txtMiddleName, org.jdesktop.beansbinding.BeanProperty.create("text"), "agentMN");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agtLastName}"), txtLastName, org.jdesktop.beansbinding.BeanProperty.create("text"), "agentLN");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agtBusPhone}"), txtBusPhone, org.jdesktop.beansbinding.BeanProperty.create("text"), "agentP");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agtEmail}"), txtEmail, org.jdesktop.beansbinding.BeanProperty.create("text"), "agentE");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        cmbPosition.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Junior Agent", "Intermediate Agent", "Senior Agent", "Inactive" }));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agtPosition}"), cmbPosition, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"), "agentPo");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        lblId.setText("ID:");

        lblFirstName.setText("First Name:");

        lblMiddle.setText("Middle Name:");

        lblLastName.setText("Last Name:");

        lblBusPhone.setText("Bus. Phone:");

        lblEmail.setText("Email:");

        lblPosition.setText("Position:");

        lblAgencyId.setText("Agency ID:");

        btnAgentsNew.setText("New");
        btnAgentsNew.setName(""); // NOI18N
        btnAgentsNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgentsNewActionPerformed(evt);
            }
        });

        btnAgentsAdd.setText("Add");
        btnAgentsAdd.setEnabled(false);
        btnAgentsAdd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAgentsAddMouseClicked(evt);
            }
        });
        btnAgentsAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgentsAddActionPerformed(evt);
            }
        });

        btnAgentsUpdate.setText("Update");
        btnAgentsUpdate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAgentsUpdateMouseClicked(evt);
            }
        });

        jLabel1.setText("Inactive Agents ID :");

        cmbAgnts.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbAgntsItemStateChanged(evt);
            }
        });
        cmbAgnts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAgntsActionPerformed(evt);
            }
        });

        jLabel2.setText("Active Agents ID :");

        cmbActiveAgents.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbActiveAgentsActionPerformed(evt);
            }
        });

        jScrollPane5.setViewportView(lCust);

        btnMoveCust.setText(">>");
        btnMoveCust.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMoveCustActionPerformed(evt);
            }
        });

        lSelectCust.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane6.setViewportView(lSelectCust);

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, agenciesList, cmbAgency, "agencyB");
        jComboBoxBinding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabAgents, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.agencyId}"), cmbAgency, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"), "agencySelectedB");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        btnAgentsDel.setText("Delete");
        btnAgentsDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgentsDelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pAgentsLayout = new javax.swing.GroupLayout(pAgents);
        pAgents.setLayout(pAgentsLayout);
        pAgentsLayout.setHorizontalGroup(
            pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(pAgentsLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addComponent(lblMiddle)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 115, Short.MAX_VALUE)
                        .addComponent(txtMiddleName, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addComponent(lblLastName)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pAgentsLayout.createSequentialGroup()
                                    .addComponent(lblPosition)
                                    .addGap(12, 12, 12))
                                .addComponent(lblBusPhone, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addComponent(lblEmail))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtBusPhone, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbPosition, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblFirstName)
                            .addComponent(lblId))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtFirstName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pAgentsLayout.createSequentialGroup()
                                .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblAgencyId)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cmbAgency, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(38, 38, 38)
                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnAgentsUpdate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAgentsAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAgentsNew, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAgentsDel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(134, 134, 134)
                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cmbAgnts, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnMoveCust)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cmbActiveAgents, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(120, 120, 120)
                        .addComponent(jLabel2)))
                .addGap(84, 84, 84))
        );

        pAgentsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtBusPhone, txtEmail, txtFirstName, txtLastName, txtMiddleName});

        pAgentsLayout.setVerticalGroup(
            pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pAgentsLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cmbActiveAgents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbAgnts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pAgentsLayout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(btnMoveCust)
                                .addGap(106, 106, 106))
                            .addComponent(jScrollPane5)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)))
                    .addGroup(pAgentsLayout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pAgentsLayout.createSequentialGroup()
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(cmbAgency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblAgencyId)
                                    .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblId))
                                .addGap(18, 18, 18)
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblFirstName)
                                    .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(9, 9, 9)
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblMiddle)
                                    .addComponent(txtMiddleName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblLastName))
                                .addGap(9, 9, 9)
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtBusPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblBusPhone))
                                .addGap(7, 7, 7)
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblEmail))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pAgentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(cmbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblPosition)))
                            .addGroup(pAgentsLayout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(btnAgentsNew, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnAgentsAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnAgentsUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnAgentsDel, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addGap(62, 62, 62))
        );

        pAgentsLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtBusPhone, txtEmail, txtFirstName, txtLastName, txtMiddleName});

        btnAgentsNew.getAccessibleContext().setAccessibleParent(this);

        tpAll.addTab("   Agents   ", pAgents);

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, packagesList, tabPackages, "packagestable");
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${packageId}"));
        columnBinding.setColumnName("Package Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pkgName}"));
        columnBinding.setColumnName("Pkg Name");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pkgStartDate}"));
        columnBinding.setColumnName("Pkg Start Date");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pkgEndDate}"));
        columnBinding.setColumnName("Pkg End Date");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pkgBasePrice}"));
        columnBinding.setColumnName("Pkg Base Price");
        columnBinding.setColumnClass(java.math.BigDecimal.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pkgAgencyCommission}"));
        columnBinding.setColumnName("Pkg Agency Commission");
        columnBinding.setColumnClass(java.math.BigDecimal.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pkgDesc}"));
        columnBinding.setColumnName("Pkg Desc");
        columnBinding.setColumnClass(String.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane3.setViewportView(tabPackages);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.pkgName}"), txtName, org.jdesktop.beansbinding.BeanProperty.create("text"), "pkgN");
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.packageId}"), txtId1, org.jdesktop.beansbinding.BeanProperty.create("text"), "pkgid");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.pkgDesc}"), jTextArea1, org.jdesktop.beansbinding.BeanProperty.create("text"), "pkgDes");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        jScrollPane4.setViewportView(jTextArea1);

        lblStartDate.setText("Start Date:");

        lblEndDate.setText("End Date:");

        lblPrice.setText("Price:");

        lblComm.setText("Commission:");

        lblDesc.setText("Description:");

        lblName.setText("Name:");

        lblId1.setText("ID:");

        btnPackagesNew.setText("New");
        btnPackagesNew.setName(""); // NOI18N
        btnPackagesNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPackagesNewActionPerformed(evt);
            }
        });

        btnPackagesAdd.setText("Add");
        btnPackagesAdd.setEnabled(false);
        btnPackagesAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPackagesAddActionPerformed(evt);
            }
        });

        btnPackagesUpdate.setText("Update");
        btnPackagesUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPackagesUpdateActionPerformed(evt);
            }
        });

        btnPackagesDel.setText("Delete");
        btnPackagesDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPackagesDelActionPerformed(evt);
            }
        });

        txtStartDate.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.pkgStartDate}"), txtStartDate, org.jdesktop.beansbinding.BeanProperty.create("text"), "pkgStartDateBinding");
        binding.setSourceUnreadableValue(null);
        binding.setConverter(convert1);
        bindingGroup.addBinding(binding);

        txtEndDate.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.pkgEndDate}"), txtEndDate, org.jdesktop.beansbinding.BeanProperty.create("text"), "endDate");
        binding.setConverter(convert1);
        bindingGroup.addBinding(binding);

        cbtnStartDate.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateOnlyPopupChanged(evt);
            }
        });

        cbtnEndDate.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dateOnlyPopupChanged1(evt);
            }
        });

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.pkgBasePrice}"), txtPrice, org.jdesktop.beansbinding.BeanProperty.create("text"), "priceBinding");
        binding.setSourceUnreadableValue(null);
        binding.setConverter(currencyConvert1);
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.pkgAgencyCommission}"), txtCommission, org.jdesktop.beansbinding.BeanProperty.create("text"), "commissionBinding");
        binding.setSourceUnreadableValue(null);
        binding.setConverter(currencyConvert1);
        bindingGroup.addBinding(binding);

        lProducts.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(lProducts);

        jLabel4.setText("Products belong to package ");

        jLabel3.setFont(new java.awt.Font("宋体", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 0, 51));
        jLabel3.setToolTipText("");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tabPackages, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.packageId}"), jLabel3, org.jdesktop.beansbinding.BeanProperty.create("text"), "lblPakIdBinding");
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);

        jLabel3.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jLabel3PropertyChange(evt);
            }
        });

        jLabel5.setText("Product and Supplier");

        lProductSupplier.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lProductSupplier.setVerifyInputWhenFocusTarget(false);
        jScrollPane7.setViewportView(lProductSupplier);

        btnMoveprod.setText(">>");
        btnMoveprod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMoveprodActionPerformed(evt);
            }
        });

        btnAddProd.setText("<<");
        btnAddProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddProdActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pPackagesLayout = new javax.swing.GroupLayout(pPackages);
        pPackages.setLayout(pPackagesLayout);
        pPackagesLayout.setHorizontalGroup(
            pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3)
            .addGroup(pPackagesLayout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDesc, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblPrice)
                        .addComponent(lblComm)
                        .addComponent(lblStartDate)
                        .addComponent(lblEndDate)
                        .addComponent(lblId1)))
                .addGap(18, 18, 18)
                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(txtId1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblName)
                        .addGap(28, 28, 28)
                        .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtEndDate)
                            .addComponent(txtStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCommission, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(pPackagesLayout.createSequentialGroup()
                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbtnStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cbtnEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(27, 27, 27)
                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnPackagesNew, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnPackagesAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(btnPackagesDel, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnPackagesUpdate)))))
                .addGap(56, 56, 56)
                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnMoveprod)
                            .addComponent(btnAddProd)))
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)))
                .addGap(9, 9, 9)
                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(131, 131, 131))
                    .addComponent(jScrollPane7)))
        );
        pPackagesLayout.setVerticalGroup(
            pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pPackagesLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblName)
                            .addComponent(txtId1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblId1)
                            .addComponent(jLabel5)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pPackagesLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))))
                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(btnMoveprod)
                        .addGap(44, 44, 44)
                        .addComponent(btnAddProd)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(pPackagesLayout.createSequentialGroup()
                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pPackagesLayout.createSequentialGroup()
                                .addGap(111, 111, 111)
                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblPrice))
                                .addGap(18, 18, 18)
                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtCommission, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblComm))
                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pPackagesLayout.createSequentialGroup()
                                        .addGap(31, 31, 31)
                                        .addComponent(lblDesc))
                                    .addGroup(pPackagesLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(pPackagesLayout.createSequentialGroup()
                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pPackagesLayout.createSequentialGroup()
                                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(pPackagesLayout.createSequentialGroup()
                                                .addGap(32, 32, 32)
                                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(lblStartDate)
                                                    .addComponent(txtStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(cbtnStartDate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(20, 20, 20)
                                                .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(lblEndDate)
                                                        .addComponent(txtEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addComponent(cbtnEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(pPackagesLayout.createSequentialGroup()
                                                .addGap(26, 26, 26)
                                                .addComponent(btnPackagesNew, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(28, 28, 28)
                                                .addComponent(btnPackagesAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(28, 28, 28)
                                        .addComponent(btnPackagesUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(pPackagesLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(pPackagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(18, 18, 18)
                                .addComponent(btnPackagesDel, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 30, Short.MAX_VALUE))))
        );

        tpAll.addTab("  Packages  ", pPackages);

        jMenu1.setText("File");

        jMenuItem1.setText("Close");
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem1MouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem1MousePressed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem2.setText("Agents");
        jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem2MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setText("Packages");
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem3MousePressed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(tpAll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tpAll, javax.swing.GroupLayout.PREFERRED_SIZE, 615, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private boolean checkEmail(String email) {
        Pattern pattern = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
        Matcher matcher = pattern.matcher(email);
        if (matcher.matches()) {
            return true;
        }
        return false;
    }

    private boolean checkPhone(String phone) {
        Pattern pattern = Pattern.compile("^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$");
        Matcher matcher = pattern.matcher(phone);
        if (matcher.matches()) {
            return true;
        }
        return false;
    }

    private boolean vaildAgentInfo() {
        String mesg = "";
        if ("".equals(txtId.getText())) {
            mesg = "Agent ID can't be empty";
            JOptionPane.showMessageDialog(null, mesg);
            return false;
        }
        if ("".equals(txtFirstName.getText())) {
            mesg = "First Name can't be empty";
            JOptionPane.showMessageDialog(null, mesg);
            return false;
        }
        if ("".equals(txtLastName.getText())) {
            mesg = "Last Name can't be empty";
            JOptionPane.showMessageDialog(null, mesg);
            return false;
        }
        if (!checkPhone(txtBusPhone.getText())) {
            mesg = "Phone address format incorrect";
            JOptionPane.showMessageDialog(null, mesg);
            return false;
        }
        if (!checkEmail(txtEmail.getText())) {
            mesg = "Email address format incorrect";
            JOptionPane.showMessageDialog(null, mesg);
            return false;
        }

        return true;
    }

    private boolean vaildPkgInfo() {
        if ("".equals(txtId1.getText())) {
            JOptionPane.showMessageDialog(null, "Package can't be empty");
            return false;
        }
        if ("".equals(txtName.getText())) {
            JOptionPane.showMessageDialog(null, "Package can't be empty");
            return false;
        }
        if ("".equals(txtStartDate.getText())) {
            JOptionPane.showMessageDialog(null, "Start date can't be empty");
            return false;
        }
        if ("".equals(txtEndDate.getText())) {
            JOptionPane.showMessageDialog(null, "End date can't be empty");
            return false;
        }
        if ("".equals(txtPrice.getText())) {
            JOptionPane.showMessageDialog(null, "Price can't be empty");
            return false;
        }
        if ("".equals(txtCommission.getText())) {
            JOptionPane.showMessageDialog(null, "Commission can't be empty");
            return false;
        }
        if (validNumber(txtPrice.getText())) {
            JOptionPane.showMessageDialog(null, "Number only");
            return false;
        }
        if (validNumber(txtCommission.getText())) {
            JOptionPane.showMessageDialog(null, "Number only");
            return false;
        }
        if (Integer.parseInt(txtCommission.getText()) > Integer.parseInt(txtPrice.getText())) {
            JOptionPane.showMessageDialog(null, "Commission must be less than price");
            return false;
        }
        Convert c = new Convert();
        if (c.convertReverse(txtStartDate.getText()).after(c.convertReverse(txtEndDate.getText()))) {
            JOptionPane.showMessageDialog(null, "End date must be late than start date");
            return false;
        }
        return true;

    }

    private boolean validNumber(String num) {
        Pattern pattern = Pattern.compile("^(\\+|-)?([0-9]+(\\.[0-9]+))$");
        Matcher matcher = pattern.matcher(num);
        if (matcher.matches()) {
            return true;
        }
        return false;

    }

    public void setDate(Date date) {
        String dateString = "";
        if (date != null) {
            dateString = new SimpleDateFormat("yyyy-MM-dd").format(date);
        }
        txtStartDate.setText(dateString);
        cbtnStartDate.setTargetDate(date);
    }

    public void setDate1(Date date) {
        String dateString = "";
        if (date != null) {
            dateString = new SimpleDateFormat("yyyy-MM-dd").format(date);
        }
        txtEndDate.setText(dateString);
        cbtnEndDate.setTargetDate(date);
    }
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButton1MouseClicked

    private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MouseClicked
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jMenuItem1MouseClicked

    private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MousePressed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jMenuItem1MousePressed

    private void jMenuItem2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem2MousePressed
        // TODO add your handling code here:
        tpAll.setSelectedIndex(0);
    }//GEN-LAST:event_jMenuItem2MousePressed

    private void jMenuItem3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MousePressed
        // TODO add your handling code here:
        tpAll.setSelectedIndex(1);
    }//GEN-LAST:event_jMenuItem3MousePressed

    private void dateOnlyPopupChanged1(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateOnlyPopupChanged1
        // TODO add your handling code here:
        if (evt.getNewValue() instanceof Date) {
            setDate1((Date) evt.getNewValue());
        }
    }//GEN-LAST:event_dateOnlyPopupChanged1

    private void dateOnlyPopupChanged(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateOnlyPopupChanged
        // TODO add your handling code here:
        if (evt.getNewValue() instanceof Date) {
            setDate((Date) evt.getNewValue());
        }
    }//GEN-LAST:event_dateOnlyPopupChanged

    private void btnPackagesDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPackagesDelActionPerformed
        // TODO add your handling code here:
        DBAccess databaseaccess = new DBAccess();
        databaseaccess.deletePkgData(getPkgData());
        int[] selected = tabPackages.getSelectedRows();
        List<travelexperts.Packages> toRemove = new ArrayList<travelexperts.Packages>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            travelexperts.Packages a = packagesList.get(tabPackages.convertRowIndexToModel(selected[idx]));
            toRemove.add(a);
            entityManager.remove(a);
        }
        packagesList.removeAll(toRemove);
    }//GEN-LAST:event_btnPackagesDelActionPerformed

    private void btnPackagesUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPackagesUpdateActionPerformed
        // TODO add your handling code here
        if (vaildPkgInfo()) {
            DBAccess databaseaccess = new DBAccess();
            databaseaccess.updatePackagesData(getPkgData());
        }
    }//GEN-LAST:event_btnPackagesUpdateActionPerformed

    private void btnPackagesAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPackagesAddActionPerformed
        // TODO add your handling code here:
        if (vaildPkgInfo()) {
            DBAccess databaseaccess = new DBAccess();
            databaseaccess.insertPkgsData(getPkgData());
            btnPackagesAdd.setEnabled(false);
            btnPackagesNew.setEnabled(true);
        }
    }//GEN-LAST:event_btnPackagesAddActionPerformed

    private void btnPackagesNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPackagesNewActionPerformed
        // TODO add your handling code here:
        travelexperts.Packages a = new travelexperts.Packages();
        entityManager.persist(a);
        packagesList.add(a);
        int row = packagesList.size() - 1;
        tabPackages.setRowSelectionInterval(row, row);
        tabPackages.scrollRectToVisible(tabPackages.getCellRect(row, 0, true));
        btnPackagesAdd.setEnabled(true);
        btnPackagesNew.setEnabled(false);
    }//GEN-LAST:event_btnPackagesNewActionPerformed

    private void btnAgentsUpdateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAgentsUpdateMouseClicked
        // TODO add your handling code here:
        if (vaildAgentInfo()) {
            DBAccess databaseaccess = new DBAccess();
            databaseaccess.updateAgtData(getAgntData());
            refreshActiveAgent();
            refreshInactiveAgent();
        }
    }//GEN-LAST:event_btnAgentsUpdateMouseClicked

    private void btnAgentsAddMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAgentsAddMouseClicked
        // TODO add your handling code here:
        if (vaildAgentInfo()) {
            DBAccess databaseaccess = new DBAccess();
            databaseaccess.insertAgtData(getAgntData());
            btnAgentsAdd.setEnabled(false);
            btnAgentsNew.setEnabled(true);
            refreshActiveAgent();
            refreshInactiveAgent();
        }
    }//GEN-LAST:event_btnAgentsAddMouseClicked

    private void btnAgentsNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgentsNewActionPerformed
        // TODO add your handling code here:
        // clearTxt();
        btnAgentsAdd.setEnabled(true);
        btnAgentsNew.setEnabled(false);
        travelexperts.Agents a = new travelexperts.Agents();
        entityManager.persist(a);
        agentsList.add(a);
        int row = agentsList.size() - 1;
        tabAgents.setRowSelectionInterval(row, row);
        tabAgents.scrollRectToVisible(tabAgents.getCellRect(row, 0, true));
    }//GEN-LAST:event_btnAgentsNewActionPerformed

    private void tabAgentsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabAgentsMousePressed
        // TODO add your handling code here:
        btnAgentsAdd.setEnabled(false);
        btnAgentsNew.setEnabled(true);
    }//GEN-LAST:event_tabAgentsMousePressed

    private void cmbAgntsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbAgntsItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbAgntsItemStateChanged

    private void btnAgentsDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgentsDelActionPerformed
        // TODO add your handling code here:

        try {
            DBAccess databaseaccess = new DBAccess();
            if (databaseaccess.selectCustomersData(txtId.getText()).isEmpty()) {
                DBAccess deldatabaseaccess = new DBAccess();
                deldatabaseaccess.deleteAgtData(getAgntData());
                int[] selected = tabAgents.getSelectedRows();
                List<travelexperts.Agents> toRemove = new ArrayList<travelexperts.Agents>(selected.length);
                for (int idx = 0; idx < selected.length; idx++) {
                    travelexperts.Agents a = agentsList.get(tabAgents.convertRowIndexToModel(selected[idx]));
                    toRemove.add(a);
                    entityManager.remove(a);
                }
                agentsList.removeAll(toRemove);
            } else {
                JOptionPane.showMessageDialog(null, "Can't delete. This agent links to customers.", "AlertBox", JOptionPane.WARNING_MESSAGE);
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        refreshInactiveAgent();
        refreshActiveAgent();
    }//GEN-LAST:event_btnAgentsDelActionPerformed

    private void btnAgentsAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgentsAddActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnAgentsAddActionPerformed

    private void cmbAgntsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAgntsActionPerformed
        // TODO add your handling code here:
        refreshInactiveCust();
    }//GEN-LAST:event_cmbAgntsActionPerformed

    private void cmbActiveAgentsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbActiveAgentsActionPerformed
        // TODO add your handling code here:
        refreshActiveCust();
    }//GEN-LAST:event_cmbActiveAgentsActionPerformed

    private void btnMoveCustActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveCustActionPerformed
        // TODO add your handling code here:
        DBAccess dbCust = new DBAccess();
        Customers_Data tmpCust = (Customers_Data) lCust.getSelectedValue();
        tmpCust.setAgentId(Integer.parseInt(((Agent_Data) cmbActiveAgents.getSelectedItem()).getAgtId()));
        dbCust.updateCustomersData(tmpCust);
        refreshActiveCust();
        refreshInactiveCust();
    }//GEN-LAST:event_btnMoveCustActionPerformed

    private void jLabel3PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jLabel3PropertyChange
        // TODO add your handling code here:
        refreshProduct();
        refreshProductSupplier();
    }//GEN-LAST:event_jLabel3PropertyChange

    private void btnMoveprodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveprodActionPerformed
        // TODO add your handling code here:
        DBAccess db = new DBAccess();
        ProdSup_Data psd = new ProdSup_Data();
        psd = (ProdSup_Data) lProducts.getSelectedValue();
        System.out.println(psd.getProductSupplierId());
        lProductSupplier.setModel(addListModel(lProductSupplier, psd));
        lProducts.setModel(removeListModel(lProducts, psd));
        db.deletePkgProSupData(getPkgProdSupp(psd));
    }//GEN-LAST:event_btnMoveprodActionPerformed

    private void btnAddProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddProdActionPerformed
        // TODO add your handling code here:
        DBAccess db = new DBAccess();
        ProdSup_Data psd = new ProdSup_Data();
        psd = (ProdSup_Data) lProductSupplier.getSelectedValue();
        lProductSupplier.setModel(removeListModel(lProductSupplier, psd));
        lProducts.setModel(addListModel(lProducts, psd));
        db.insertPkgPoSuprData(getPkgProdSupp(psd));
    }//GEN-LAST:event_btnAddProdActionPerformed
    private DefaultListModel addListModel(javax.swing.JList list, Object o) {
        DefaultListModel listModel = new DefaultListModel();
        listModel = (DefaultListModel) list.getModel();
        listModel.addElement(o);
        return listModel;
    }

    private DefaultListModel removeListModel(javax.swing.JList list, Object o) {
        DefaultListModel listModel = new DefaultListModel();
        listModel = (DefaultListModel) list.getModel();
        listModel.removeElement(o);
        return listModel;
    }

    private PkgProSup_Data getPkgProdSupp(ProdSup_Data ps) {
        PkgProSup_Data pps = new PkgProSup_Data();
        pps.setPackageId(Integer.parseInt(txtId1.getText()));
        pps.setProductSupplierId(ps.getProductSupplierId());
        return pps;
    }

    private Agent_Data getAgntData() {
        Agent_Data agnt = new Agent_Data();
        agnt.setAgencyId(cmbAgency.getSelectedItem().toString());
        agnt.setAgtBusPhone(txtBusPhone.getText());
        agnt.setAgtEmail(txtEmail.getText());
        agnt.setAgtFirstNm(txtFirstName.getText());
        agnt.setAgtId(txtId.getText());
        agnt.setAgtLastNm(txtLastName.getText());
        if ("".equals(txtMiddleName.getText())) {
            agnt.setAgtMiddleNm("");
        } else {
            agnt.setAgtMiddleNm(txtMiddleName.getText());
        }
        agnt.setAgtPosition(cmbPosition.getSelectedItem().toString());
        return agnt;
    }

    private Packages_Data getPkgData() {
        Packages_Data pkg = new Packages_Data();
        pkg.setPackageId(Integer.parseInt(txtId1.getText()));
        pkg.setPkgName(txtName.getText());
        pkg.setPkgAgencyCommission(new currencyConvert().convertReverse(txtCommission.getText()));
        pkg.setPkgBasePrice(new currencyConvert().convertReverse(txtPrice.getText()));
        pkg.setPkgStartDate(txtStartDate.getText());
        pkg.setPkgEndDate(txtEndDate.getText());
        pkg.setPkgDesc(jTextArea1.getText());
        return pkg;
    }

    private void refreshInactiveAgent() {
        DBAccess dbAgent = new DBAccess();
        DefaultComboBoxModel cmbModel = new DefaultComboBoxModel();
        cmbModel.removeAllElements();
        cmbAgnts.setModel(cmbModel);
        try {
            ArrayList<Agent_Data> inactiveAgent_Datas = dbAgent.selectInactiveAgentData();
            for (int i = 0; i < inactiveAgent_Datas.size(); i++) {
                cmbModel.addElement(inactiveAgent_Datas.get(i));
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        cmbAgnts.setModel(cmbModel);
        refreshInactiveCust();

    }

    private void refreshActiveAgent() {
        DBAccess dbAgent = new DBAccess();
        DefaultComboBoxModel cmbModel = new DefaultComboBoxModel();
        cmbModel.removeAllElements();
        cmbActiveAgents.setModel(cmbModel);
        try {
            ArrayList<Agent_Data> activeAgent_Datas = dbAgent.selectActiveAgentData();
            for (int i = 0; i < activeAgent_Datas.size(); i++) {
                cmbModel.addElement(activeAgent_Datas.get(i));
            }
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        cmbActiveAgents.setModel(cmbModel);
        refreshActiveCust();

    }

    private void refreshInactiveCust() {
        DBAccess dbAgent = new DBAccess();
        DefaultListModel listModel = new DefaultListModel();
        listModel.clear();
        lCust.setModel(listModel);
        try {
            ArrayList<Customers_Data> custDatas = dbAgent.selectCustomersData(((Agent_Data) cmbAgnts.getSelectedItem()).getAgtId());

            for (int i = 0; i < custDatas.size(); i++) {
                listModel.addElement(custDatas.get(i));
            }
            lCust.setModel(listModel);
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void refreshActiveCust() {
        DBAccess dbAgent = new DBAccess();
        DefaultListModel listModel = new DefaultListModel();
        listModel.clear();
        lSelectCust.setModel(listModel);
        {
            try {
                ArrayList<Customers_Data> custDatas = dbAgent.selectCustomersData(((Agent_Data) cmbActiveAgents.getSelectedItem()).getAgtId());

                for (int i = 0; i < custDatas.size(); i++) {
                    listModel.addElement(custDatas.get(i));
                }
                lSelectCust.setModel(listModel);
            } catch (SQLException ex) {
                Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void refreshProduct() {
        DBAccess dbProd = new DBAccess();
        DefaultListModel listModel = new DefaultListModel();
        listModel.clear();
        lProducts.setModel(listModel);
        try {
            ArrayList<ProdSup_Data> prodDatas = dbProd.selectProductSupplierDataInPkg(txtId1.getText(), true);
            for (int i = 0; i < prodDatas.size(); i++) {
                listModel.addElement(prodDatas.get(i));
            }
            lProducts.setModel(listModel);
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void refreshProductSupplier() {
        DBAccess dbProdSupp = new DBAccess();
        DefaultListModel listModel = new DefaultListModel();
        listModel.clear();
        lProductSupplier.setModel(listModel);
        try {
            ArrayList<ProdSup_Data> prodSuppDatas = dbProdSupp.selectProductSupplierDataNotInPkg();
            for (int i = 0; i < prodSuppDatas.size(); i++) {
                listModel.addElement(prodSuppDatas.get(i));
            }
            if (!"".equals(txtId1.getText())) {
                DBAccess dbProd = new DBAccess();
                ArrayList<ProdSup_Data> prodDatas = dbProd.selectProductSupplierDataInPkg(txtId1.getText(), true);
                for (int i = 0; i < prodDatas.size(); i++) {
                    listModel.removeElement(prodDatas.get(i));
                }
            }
            lProductSupplier.setModel(listModel);
        } catch (SQLException ex) {
            Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.List<travelexperts.Agencies> agenciesList;
    private javax.persistence.Query agenciesQuery;
    private java.util.List<travelexperts.Agents> agentsList;
    private java.util.List<travelexperts.Agents> agentsList1;
    private java.util.List<travelexperts.Agents> agentsList2;
    private javax.persistence.Query agentsQuery;
    private javax.persistence.Query agentsQuery1;
    private javax.persistence.Query agentsQuery2;
    private javax.swing.JButton btnAddProd;
    private javax.swing.JButton btnAgentsAdd;
    private javax.swing.JButton btnAgentsDel;
    private javax.swing.JButton btnAgentsNew;
    private javax.swing.JButton btnAgentsUpdate;
    private javax.swing.JButton btnMoveCust;
    private javax.swing.JButton btnMoveprod;
    private javax.swing.JButton btnPackagesAdd;
    private javax.swing.JButton btnPackagesDel;
    private javax.swing.JButton btnPackagesNew;
    private javax.swing.JButton btnPackagesUpdate;
    private net.sourceforge.jcalendarbutton.JCalendarButton cbtnEndDate;
    private net.sourceforge.jcalendarbutton.JCalendarButton cbtnStartDate;
    private javax.swing.JComboBox cmbActiveAgents;
    private javax.swing.JComboBox cmbAgency;
    private javax.swing.JComboBox cmbAgnts;
    private javax.swing.JComboBox cmbPosition;
    private travelexperts.Convert convert1;
    private travelexperts.currencyConvert currencyConvert1;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JList lCust;
    private javax.swing.JList lProductSupplier;
    private javax.swing.JList lProducts;
    private javax.swing.JList lSelectCust;
    private javax.swing.JLabel lblAgencyId;
    private javax.swing.JLabel lblBusPhone;
    private javax.swing.JLabel lblComm;
    private javax.swing.JLabel lblDesc;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblEndDate;
    private javax.swing.JLabel lblFirstName;
    private javax.swing.JLabel lblId;
    private javax.swing.JLabel lblId1;
    private javax.swing.JLabel lblLastName;
    private javax.swing.JLabel lblMiddle;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblPosition;
    private javax.swing.JLabel lblPrice;
    private javax.swing.JLabel lblStartDate;
    private javax.swing.JPanel pAgents;
    private javax.swing.JPanel pPackages;
    private java.util.List<travelexperts.Packages> packagesList;
    private javax.persistence.Query packagesQuery;
    private javax.swing.JTable tabAgents;
    private javax.swing.JTable tabPackages;
    private javax.swing.JTabbedPane tpAll;
    private javax.swing.JTextField txtBusPhone;
    private javax.swing.JTextField txtCommission;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEndDate;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtId1;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JTextField txtMiddleName;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPrice;
    private javax.swing.JTextField txtStartDate;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
